﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Dropthings.DataAccess;

namespace Dropthings.Business.Activities.WidgetActivities
{
	public partial class GetWidgetActivity: Activity
	{
        public int WidgetId
        {
            get { return (int)GetValue(WidgetIdProperty); }
            set { SetValue(WidgetIdProperty, value); }
        }

        public static readonly DependencyProperty WidgetIdProperty =
            DependencyProperty.Register("WidgetId", typeof(int), typeof(GetWidgetActivity));

        public Widget Widget
        {
            get { return (Widget)GetValue(WidgetProperty); }
            set { SetValue(WidgetProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WidgetProperty =
            DependencyProperty.Register("Widget", typeof(Widget), typeof(GetWidgetActivity));

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            this.Widget = DatabaseHelper.GetSingle<Widget, int>(DatabaseHelper.SubsystemEnum.Widget,
                this.WidgetId, LinqQueries.CompiledQuery_GetWidgetById);

            return ActivityExecutionStatus.Closed;
        }

        public GetWidgetActivity()
		{
			InitializeComponent();
		}
	}
}
